import { Module } from '@nestjs/common'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { APP_GUARD } from '@nestjs/core'
import { TypeOrmModule } from '@nestjs/typeorm'
import { ConfigEnum } from '@/enum/config.enum'
import { AuthModule } from './auth/auth.module'
import { JwtAuthGuard } from './guards/jwt-auth.guard'
import { PermissionGuard } from './guards/permission.guard'
import { LoggerModule } from './logger/logger.module'
import { MenuModule } from './menu/menu.module'
import { PermissionModule } from './permission/permission.module'
import { RolesModule } from './roles/roles.module'
import { RouteModule } from './route/route.module'
import { UsersModule } from './users/users.module'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import AppConfig from './config'
@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      load: AppConfig,
    }), // 配置模块
    TypeOrmModule.forRootAsync({
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => configService.get(ConfigEnum.DB_CONFIG),
    }),
    UsersModule,
    AuthModule,
    MenuModule,
    LoggerModule,
    RolesModule,
    RouteModule,
    PermissionModule,
  ],
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
    {
      provide: APP_GUARD,
      useClass: PermissionGuard,
    },
  ],
})
export class AppModule {}
